const qs = require('querystring');
function bodyParser(req, res, next) {
    //中间件的逻辑代码
    let str = '';
    req.on('data', (chunk) => {
        str += chunk;
    })
    //3.监听end事件
    req.on('end', () => {
        //把字符串的请求数据，解析成对象格式
        const body = qs.parse(str);
        req.body = body;//挂载
        next();
    })
}

module.exports.bodyParser = bodyParser;